home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / dsik_pas.zip / TS.ASM < prev    next >
Assembly Source File  |  1994-07-28  |  8KB  |  240 lines

  1. ;▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  2. ; ts.asm - timer service routines
  3. ;▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  4.  
  5. ideal
  6. ifdef PASCAL
  7. model   large,pascal
  8. else
  9. model   large,c
  10. endif
  11. p386
  12.  
  13. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  14. ; Data segment
  15. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  16. dataseg
  17.  
  18. oldtimer        dd      ?               ; BIOS INT 08h routine
  19. irqcallback     dd      ?               ; user defined callback routine
  20. irqactive       dw      ?               ; callback routine active flag
  21. irqenabled      dw      0               ; timer service enabled flag
  22. timerspeed      dw      ?               ; timer speed in clock ticks
  23. timercount      dw      ?               ; timer counter used to call the
  24.                                         ; old BIOS timer interrupt service
  25.  
  26. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  27. ; Code segment
  28. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  29. codeseg
  30.  
  31. global  TSInit:proc                     ; initialize the routines
  32. global  TSDone:proc                     ; deinitialize the routines
  33. global  TSSetRate:proc                  ; set the callback rate in hertz
  34. global  TSSetRoutine:proc               ; set the callback routine address
  35. global  TSRestoreTime:proc              ; restore the time/date
  36.  
  37. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  38. ; TSInit - initialize the timer service routines
  39. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  40. proc    TSInit
  41.         cmp     [irqenabled],0          ; services already enabled? exit
  42.         jne     tsinitd0
  43.         lea     ax,[dummy]              ; set the default callback routine
  44.         mov     [word low irqcallback],ax
  45.         mov     [word high irqcallback],cs
  46.         mov     ax,3508h                ; save the BIOS INT 08h vector
  47.         int     21h
  48.         mov     [word low oldtimer],bx
  49.         mov     [word high oldtimer],es
  50.         mov     [irqactive],0
  51.         push    ds                      ; set our timer interrupt vector
  52.         mov     ax,cs
  53.         mov     ds,ax
  54.         lea     dx,[timerhandler]
  55.         mov     ax,2508h
  56.         int     21h
  57.         pop     ds
  58.         cli                             ; reprogram the PIT timer0 rate
  59.         mov     al,36h                  ; to 18.2 Hertz (default)
  60.         out     43h,al
  61.         xor     al,al
  62.         out     40h,al
  63.         out     40h,al
  64.         sti
  65.         mov     [timerspeed],0FFFFh
  66.         inc     [irqenabled]
  67. tsinitd0:
  68.         ret
  69. endp    TSInit
  70.  
  71. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  72. ; TSDone - deinitialize the timer services
  73. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  74. proc    TSDone
  75.         cmp     [irqenabled],0          ; services not enabled? exit
  76.         je      tsdoned0
  77.         cli                             ; restore the PIT timer0 rate
  78.         mov     al,36h                  ; to 18.2 Hertz (normal)
  79.         out     43h,al
  80.         xor     al,al
  81.         out     40h,al
  82.         out     40h,al
  83.         sti
  84.         push    ds                      ; restore the BIOS INT 08h vector
  85.         mov     dx,[word low oldtimer]
  86.         mov     ds,[word high oldtimer]
  87.         mov     ax,2508h
  88.         int     21h
  89.         pop     ds
  90.         dec     [irqenabled]
  91. tsdoned0:
  92.         ret
  93. endp    TSDone
  94.  
  95. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  96. ; TSRate - set the number of calls per seconds of the callback routine
  97. ; In:
  98. ;  Speed = speed in hertz
  99. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  100. proc    TSSetRate Speed:word
  101.         cmp     [irqenabled],0
  102.         je      tssetrated0
  103.         mov     dx,0012h                ; get the clock ticks using the
  104.         mov     ax,34DEh                ; formula: tc = 1193182/speed
  105.         div     [Speed]
  106.         mov     [timerspeed],ax
  107.         mov     dx,ax
  108.         cli                             ; program the PIT timer 0 rate
  109.         mov     al,36h
  110.         out     43h,al
  111.         mov     al,dl
  112.         out     40h,al
  113.         mov     al,dh
  114.         out     40h,al
  115.         sti
  116. tssetrated0:
  117.         ret
  118. endp    TSSetRate
  119.  
  120. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  121. ; TSSetRoutine - set the callback routine address
  122. ; In:
  123. ;  Rout = address of the callback routine
  124. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  125. proc    TSSetRoutine Rout:dword
  126.         mov     eax,[Rout]              ; change the callback routine
  127.         mov     [irqcallback],eax       ; address to the new one
  128.         ret
  129. endp
  130.  
  131. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  132. ; TSRestoreTime - restore the time/date using the CMOS
  133. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  134. proc    TSRestoreTime
  135.         mov     al,0                    ; get seconds
  136.         out     70h,al
  137.         in      al,71h
  138.         mov     ah,al
  139.         and     al,0Fh
  140.         shr     ah,4
  141.         aad
  142.         mov     dh,al
  143.  
  144.         mov     al,2                    ; get minutes
  145.         out     70h,al
  146.         in      al,71h
  147.         mov     ah,al
  148.         and     al,0Fh
  149.         shr     ah,4
  150.         aad
  151.         mov     cl,al
  152.  
  153.         mov     al,4                    ; get hours
  154.         out     70h,al
  155.         in      al,71h
  156.         mov     ah,al
  157.         and     al,0Fh
  158.         shr     ah,4
  159.         aad
  160.         mov     ch,al
  161.  
  162.         xor     dl,dl                   ; set hour:minute:secs
  163.         mov     ah,2Dh
  164.         int     21h
  165.  
  166.         mov     al,7                    ; get day
  167.         out     70h,al
  168.         in      al,71h
  169.         mov     ah,al
  170.         and     al,0Fh
  171.         shr     ah,4
  172.         aad
  173.         mov     dl,al
  174.  
  175.         mov     al,8                    ; get month
  176.         out     70h,al
  177.         in      al,71h
  178.         mov     ah,al
  179.         and     al,0Fh
  180.         shr     ah,4
  181.         aad
  182.         mov     dh,al
  183.  
  184.         mov     al,4                    ; get year
  185.         out     70h,al
  186.         in      al,71h
  187.         mov     ah,al
  188.         and     al,0Fh
  189.         shr     ah,4
  190.         aad
  191.         mov     cl,al
  192.  
  193.         xor     ch,ch                   ; set the month/day/year
  194.         add     cx,1900
  195.         mov     ah,2Bh
  196.         int     21h
  197.         ret
  198. endp    TSRestoreTime
  199.  
  200. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  201. ; timerhandler - hardware timer interrupt routine
  202. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  203. proc    timerhandler
  204.         pushad
  205.         push    ds
  206.         push    es
  207.         push    fs
  208.         push    gs
  209.         mov     ax,@data                ; get the DS data segment
  210.         mov     ds,ax
  211.         cmp     [irqactive],0           ; already active?
  212.         jne     timerhandlerd0          ; exit, don't allow recursive calls
  213.         inc     [irqactive]
  214.         call    [irqcallback]           ; call the user callback routine
  215.         dec     [irqactive]
  216. timerhandlerd0:
  217.         mov     ax,[timerspeed]
  218.         add     [timercount],ax         ; call the old BIOS timer interrupt
  219.         jnc     timerhandlerd1          ; service 18.2 times per second
  220.         pushf
  221.         call    [oldtimer]
  222.         jmp     timerhandlerd2
  223. timerhandlerd1:
  224.         mov     al,20h                  ; send acknowledge to the PIC
  225.         out     20h,al
  226. timerhandlerd2:
  227.         pop     gs
  228.         pop     fs
  229.         pop     es
  230.         pop     ds
  231.         popad
  232.         iret
  233. endp    timerhandler
  234.  
  235. proc    dummy
  236.         ret
  237. endp    dummy
  238.  
  239. end
  240.